<template>
  <DataList :cate="cate" :name="name" :single="true" :cols="cols"  />
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import linq from "linq"
import {get教师基本情况,get教师基本情况ByGH} from "@/api/教师基本情况"
import { addLx, deleteLx, updateLx, getLx } from "@/api/联系.js";
import { unzipSync } from "zlib";
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A1-2联系",
      name:'1.2 联系',
      cols: [
        { label: "通信地址", prop: "XXDZ" },
        { label: "邮政编码", prop: "XXYZBM" },
        { label: "学校网址", prop: "ZYDZ" },
        { label: "法人代表信息", prop: "法人代表信息" ,data:[
            { label: "教工号",prop:"FRDB_GH"},
            { label: "姓名", prop: "FRDB_XM" },
            { label: "职务", prop: "FRDB_ZW" },
            { label: "区号-电话号码",prop:"FRDB_DHHM"},
            { label: "区号-传真号", prop: "FRDB_CZH" },
            { label: "电子邮箱", prop: "FRDB_DZYX" },
        ]},
        
        { label: "联系人信息", prop: "联系人信息" ,data:[
            { label: "教工号",prop: "LXR_GH"},
            { label: "姓名", prop: "LXR_XM" },
            { label: "职务", prop: "LXR_ZW" },
            { label: "区号-电话号码",prop: "LXR_DHHM"},
            { label: "区号-传真号", prop: "LXR_CZH" },
            { label: "手机号",prop: "SJ"},
            { label: "电子邮箱", prop: "LXR_DZYX" },
        ]}
      ]
    };
  },
  methods:{
     /*onDlgCreated(model) {
       
      var dd = findComponent(this,"GH");
      var 专业 = linq.from(this.$root.教师基本情况).distinct("$.GH").toArray();
      dd.$attrs.items = 专业.map(item => {
        return { label: item.GH, value: item.GH};
      });
      
    },*/

      async fetchData() {
      var user = getUser();
      var datas = await getLx(user.XXID,user.CJPC);
     
      return datas;
    },
    
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model));
      return new Promise(async (resolve, reject) => {
      try{
        
        console.log(JSON.stringify(temp));
        var model = await addLx(temp);
        resolve(model);
      }catch(e){
        reject(e);
      }
       
      });
    },

      async  onChange(model, field, value) {
 
      //
         if(field == "FRDB_GH"){
         if(value == "error"){
           console.log("error")
          model.FRDB_GH=""
          model.FRDB_XM= "";
        
     
         }else{
         var d1 =  await get教师基本情况ByGH(this.$root.user.XXID,this.$root.user.CJPC,value);      
           console.log("udpate ")
          model.FRDB_GH=d1[0].GH;
          model.FRDB_XM=d1[0].XM;
         }
       }
          if(field == "LXR_GH"){
         if(value == "error"){
           console.log("error")
          model.LXR_GH="";
          model.LXR_XM="";
         }else{
         var d1 =  await get教师基本情况ByGH(this.$root.user.XXID,this.$root.user.CJPC,value);
        
           console.log("udpate ")
          model.LXR_GH= d1[0].GH;
          model.LXR_XM=d1[0].XM;
         
         
         
         }
       }
      //
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
          try{
            
          console.log(JSON.stringify(temp));
          var model = await updateLx(temp);
          resolve(model);
          }catch(e){
            
            reject(e);
          }
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteLx(temp);
          resolve();
      })
    }
        }
};
</script>
<style>
</style>